<!DOCTYPE html>
<!-- This page is used to test media src= (video and audio) performance.

  This can be used for src= (but not for MSE or EME) for content of any format
  that Chrome supports playing.

  TODO(crouleau): Rename file to contrast with mse.html. "video.html" doesn't
  make sense because sometimes we play audio-only content. Note that this will
  require a data migration on the chromeperf dashboard since "video.html" is
  included in the metrics' page names.
-->
<html>
  <body>
  </body>
  <script>
    function getQueryStrings() {
      // Gets query parameters from the URL; e.g., given a URL like:
      //
      //    http://<url>/my.html?test=123&bob=456
      //
      // returns params["test"] = 123, params["bob"]=456, etc.
      var params = {};
      // RegEx to split out values by &.
      var r = /([^&=]+)=?([^&]*)/g;
      // Lambda function for decoding extracted match values. Replaces '+' with
      // space so decodeURIComponent functions properly.
      function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
      var match;
      while (match = r.exec(window.location.search.substring(1)))
       params[d(match[1])] = d(match[2]);
      return params;
    }

    // This keeps the renderer thread busy all the time, however, it
    // stops to let other things run every 20 ms.
    function makeBusy() {
      var t = new Date().getTime();
      while (new Date().getTime() - t < 20); // 20 ms busy loop
      // Run this function again as soon as possible.
      setTimeout(makeBusy, 0);
    }

    qsParams = getQueryStrings();
    var type = qsParams['type'] || 'video';
    var testElement = document.createElement(type);
    testElement.preload = 'none';
    testElement.controls = true;
    if (qsParams['id'])
      testElement.id = qsParams['id'];
    if ('busyjs' in qsParams)
      makeBusy();
    testElement.src = qsParams['src'];
    document.body.appendChild(testElement);
  </script>
</html>
